package com.example.demo.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Type;
import org.joda.money.Money;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

//接收前端（modifyDrink）的参数

//@Setter
//@Getter

@Entity
@Table(name = "t_drink")
@Data
@NoArgsConstructor//构造函数
@AllArgsConstructor
@Builder//可以采用链式写法
public class Drink {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer id;//饮品编号

//    @Column(name = "name")

    @NotBlank(message = "饮品名字不能为空")
//    @Length(max=20)
    public String name;//饮品名称

    @Column
    @Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmount",
            parameters = {@org.hibernate.annotations.Parameter(name = "currencyCode", value = "CNY")})
    @NotNull
    public Money price;//饮品价格

    //单向的多对一
    @ManyToOne
    @JsonIgnoreProperties(value={"hibernateLazyInitializer"})
    public Category category;//分类

}
